package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.ContractParty;
import com.ruoyi.contract.service.IContractPartyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 签约方Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/ContractParty")
public class ContractPartyController extends BaseController
{
    @Autowired
    private IContractPartyService contractPartyService;

    /**
     * 查询签约方列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractParty contractParty)
    {
        startPage();
        List<ContractParty> list = contractPartyService.selectContractPartyList(contractParty);
        return getDataTable(list);
    }

    /**
     * 导出签约方列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:export')")
    @Log(title = "签约方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractParty contractParty)
    {
        List<ContractParty> list = contractPartyService.selectContractPartyList(contractParty);
        ExcelUtil<ContractParty> util = new ExcelUtil<ContractParty>(ContractParty.class);
        util.exportExcel(response, list, "签约方数据");
    }

    /**
     * 获取签约方详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:query')")
    @GetMapping(value = "/{contractPartyId}")
    public AjaxResult getInfo(@PathVariable("contractPartyId") Long contractPartyId)
    {
        return success(contractPartyService.selectContractPartyByContractPartyId(contractPartyId));
    }

    /**
     * 新增签约方
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:add')")
    @Log(title = "签约方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractParty contractParty)
    {
        return contractPartyService.insertContractParty(contractParty);
    }

    /**
     * 修改签约方
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:edit')")
    @Log(title = "签约方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractParty contractParty)
    {
        return toAjax(contractPartyService.updateContractParty(contractParty));
    }

    /**
     * 删除签约方
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractParty:remove')")
    @Log(title = "签约方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractPartyIds}")
    public AjaxResult remove(@PathVariable Long[] contractPartyIds)
    {
        return toAjax(contractPartyService.deleteContractPartyByContractPartyIds(contractPartyIds));
    }
}
